package com.shejimoshi.抽象工厂模式;

import com.shejimoshi.抽象工厂模式.common.Article;
import com.shejimoshi.抽象工厂模式.common.Video;
import com.shejimoshi.抽象工厂模式.例子.CourseFactory;
import com.shejimoshi.抽象工厂模式.例子.JavaCourseFactory;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        CourseFactory courseFactory = new JavaCourseFactory();
        Video video = courseFactory.getVideo();
        Article article = courseFactory.getArticle();
        video.produce();
        article.produce();

        // 也可以利用反射机制和配置文件，当需要修改具体工厂的时候就不需要修改客户端代码，只改配置文件即可
        // 从配置文件或数据库等外部渠道获取具体工厂类名
        String factoryName = "com.shejimoshi.抽象工厂模式.例子.JavaCourseFactory";
        // 通过反射机制获取工厂类
        Class c = Class.forName(factoryName);
        CourseFactory courseFactoryReflact = (CourseFactory) c.newInstance();
        Video videoReflact = courseFactoryReflact.getVideo();
        Article articleReflact = courseFactoryReflact.getArticle();
        videoReflact.produce();
        articleReflact.produce();
    }
}